import {
  BasicColumn
} from '/@/components/Table';
import {
  FormSchema
} from '/@/components/Table';
import {
  rules
} from '/@/utils/helper/validator';
import {
  render
} from '/@/utils/common/renderUtils';
import {
  JVxeTypes,
  JVxeColumn
} from '/@/components/jeecg/JVxeTable/types'

//列表数据
export const columns: BasicColumn[] = [
  //  {
  //   title: '订单类型ID',
  //   align:"center",
  //   dataIndex: 'billTypeId'
  //  },
  
  {
    title: '订单类型',
    align: "center",
    width: 100,
    sorter: true,
    dataIndex: 'billTypeName'
  },
  {
    title: '订单渠道',
    align: "center",
    width: 100,
    sorter: true,
    dataIndex: 'orderChannel',
    customRender: ({ text }) => { return render.renderDict(text, 'order_center_order_channel'); },
  },
  {
    title: '经营平台',
    align: "center",
    width: 100,
    sorter: true,
    dataIndex: 'orderBusPlatform'
  },
  {
    title: '订单创建人',
    align: "center",
    width: 100,
    sorter: true,
    dataIndex: 'orderCreateBy',
  },
  // {
  //   title: '计划类型',
  //   align: "center",
  //   dataIndex: 'planType',
  //   width: 100,
  //   customRender: ({ text }) => {
  //     return text == 1 ? '标准采购' : text == 2 ? '委外采购' : text == 3 ? '燃热自制' : text == 4 ? '厨电自制' : text == 5 ? '热能采购' : text == 6 ? '热能自制' : ''
  //   },
  // },
  {
    title: '订单编号',
    align: "center",
    sorter: true,
    width: 140,
    dataIndex: 'billCode'
  },
  {
    title: '订单行号',
    align: "center",
    sorter: true,
    dataIndex: 'rowNum',
    width: 80
  },
  {
    title: '产品编号',
    align: "center",
    sorter: true,
    width: 140,
    dataIndex: 'materialCode'
  },
  {
    title: '产品名称',
    align: "center",
    sorter: true,
    dataIndex: 'materialName',
    width: 200
  },
  {
    title: '规格',
    align: "center",
    sorter: true,
    dataIndex: 'spec',
    width: 120,
  },
  {
    title: '单位',
    align: "center",
    dataIndex: 'unitName',
    width: 100
  },
  {
    title: '订单数量',
    align: "center",
    dataIndex: 'orderQuantity',
    width: 100
  },
  {
    title: '已排产数',
    align: "center",
    dataIndex: 'productQuantity',
    width: 100
  },
  {
    title: '关闭数量',
    align: "center",
    dataIndex: 'closeQuantity',
    width: 100
  },
  {
    title: '已入库数',
    align: "center",
    dataIndex: 'storageQuantity',
    width: 100
  },
  {
    title: '已出货数',
    align: "center",
    dataIndex: 'deliveryQuantity',
    width: 100
  },
  // {
  //   title: '订单交期',
  //   align: "center",
  //   sorter: true,
  //   dataIndex: 'orderDeliveryDate',
  //   customRender: ({ text }) => { return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text) },
  //   width: 140
  // },
  {
    title: 'D1订单交期',
    align: "center",
    sorter: true,
    dataIndex: 'd1',
    customRender: ({ text }) => { return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text) },
    width: 140
  },
  {
    title: 'D2订单交期',
    align: "center",
    sorter: true,
    dataIndex: 'd2',
    customRender: ({ text }) => { return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text) },
    width: 140
  },
  {
    title: 'D3订单交期',
    align: "center",
    sorter: true,
    dataIndex: 'd3',
    customRender: ({ text }) => { return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text) },
    width: 140
  },
  {
    title: '订单状态',
    align: "center",
    dataIndex: 'billStatus',
    sorter: true,
    width: 100,
    customRender: ({ text }) => { return render.renderDict(text, 'order_center_bill_status'); },
  },
  {
    title: '排产方式',
    align: "center",
    dataIndex: 'planMethod',
    width: 100,
  },
  {
    title: '排产单号',
    align: "center",
    dataIndex: 'planDocNo',
    width: 140,
  },
  {
    title: '和云销售订单号',
    align: "center",
    dataIndex: 'hjSerialNumber'
  },
  // {
  //   title: '评审单号',
  //   align: "center",
  //   dataIndex: 'reviewCode'
  // },
  //  {
  //   title: '业务员ID',
  //   align:"center",
  //   dataIndex: 'salesmanId'
  //  },
  {
    title: '业务员',
    align: "center",
    sorter: true,
    dataIndex: 'salesmanName',
    width: 100,
  },
  //  {
  //   title: '客户ID',
  //   align:"center",
  //   dataIndex: 'customerId'
  //  },
  // {
  //   title: '客户',
  //   align: "center",
  //   sorter: true,
  //   dataIndex: 'customerName',
  //   width: 200
  // },
  //  {
  //   title: '接单组织ID',
  //   align:"center",
  //   dataIndex: 'orderOrganizationId'
  //  },
  {
    title: '接单组织',
    align: "center",
    sorter: true,
    dataIndex: 'orderOrganizationName'
  },
  //  {
  //   title: '生产组织ID',
  //   align:"center",
  //   dataIndex: 'produceOrganizationId'
  //  },
  {
    title: '生产组织',
    align: "center",
    sorter: true,
    dataIndex: 'produceOrganizationName'
  },
  {
    title: '供应类型',
    align: "center",
    sorter: true,
    dataIndex: 'supplyType',
    customRender: ({ text }) => text === 0 ? '自制' : text === 1 ? '采购' : text === 2 ? '委外' : ''
  },
  {
    title: '是否OEM',
    align: "center",
    sorter: true,
    width: 120,
    dataIndex: 'oemNot',
    customRender: ({ text }) => { return render.renderDict(text, 'yn'); },
  },
  {
    title: 'BOM是否完整',
    align: "center",
    sorter: true,
    width: 120,
    dataIndex: 'bomComplete',
    customRender: ({ text }) => { return render.renderDict(text, 'order_center_bom_complete'); },
  },
  // {
  //   title: '非完整BOM是否安排生产',
  //   align: "center",
  //   sorter: true,
  //   dataIndex: 'notCompleteProduce',
  //   width: 180,
  //   customRender: ({ text }) => { return render.renderDict(text, 'order_center_not_complete_produce'); },
  // },
  {
    title: '创建时间',
    align: "center",
    sorter: true,
    dataIndex: 'createTime',
    width: 180
  },
  // {
  //   title: '异步状态',
  //   align: "center",
  //   dataIndex: 'syncStatus',
  //   customRender: ({ text }) => {
  //     return render.renderDict(text, 'order_center_sync_status');
  //   },
  // },
  {
    title: '备注',
    align: "center",
    sorter: true,
    dataIndex: 'remark'
  },
  // {
  //   title: '第三方编码',
  //   align: "center",
  //   dataIndex: 'thirdPartyCode',
  //   ifShow: false
  // },
];
//查询数据
export const searchFormSchema: FormSchema[] = [{
  label: "订单类型",
  field: 'billTypeName',
  component: 'Input',
  colProps: {
    span: 6
  },
},
{
  label: "订单编号",
  field: 'billCode',
  component: 'Input',
  vagueSearch: true,
  colProps: {
    span: 6
  },
},
{
  label: "产品名称",
  field: 'materialName',
  component: 'Input',
  colProps: {
    span: 6
  },
},
{
  label: "订单交期",
  field: 'orderDeliveryDate',
  component: 'DatePicker',
  colProps: {
    span: 6
  },
},
{
  label: "订单状态",
  field: 'billStatus',
  component: 'JDictSelectTag',
  componentProps: {
    dictCode: "order_center_bill_status",
    stringToNumber: true,
  },
  colProps: {
    span: 6
  },
},
{
  label: "客户",
  field: 'customerName',
  component: 'Input',
  colProps: {
    span: 6
  },
},
];
//表单数据
export const formSchema: FormSchema[] = [{
  label: '订单类型ID',
  field: 'billTypeId',
  component: 'Input',
  show: false
},
{
  label: '订单类型',
  field: 'billTypeName',
  component: 'Input',
  slot: 'billTypeSlot',
  dynamicRules: () => {
    return [{
      required: true,
      message: '请输入订单类型!'
    },];
  },
},
{
  label: '订单渠道',
  field: 'orderChannel',
  component: 'JDictSelectTag',
  defaultValue: 1,
  componentProps: {
    dictCode: "order_center_order_channel",
    stringToNumber: true,
  },
},
{
  label: '计划类型',
  field: 'planType',
  component: 'Select',
  componentProps: {
    options: [{
      label: '标准采购',
      value: 1
    }, {
      label: '委外采购',
      value: 2
    }, {
      label: '燃热自制',
      value: 3
    }, {
      label: '厨电自制',
      value: 4
    }, {
      label: '热能采购',
      value: 5
    }, {
      label: '热能自制',
      value: 6
    }]
  },
},
{
  label: '订单编号',
  field: 'billCode',
  component: 'Input',
},
{
  label: '行号',
  field: 'rowNum',
  component: 'Input',
},
{
  label: '料品ID',
  field: 'materialId',
  component: 'Input',
  show: false
},
{
  label: '产品编号',
  field: 'materialCode',
  component: 'Input',
  slot: 'materialSlot'
},
{
  label: '产品名称',
  field: 'materialName',
  component: 'Input',
},
{
  label: '规格',
  field: 'spec',
  component: 'Input',
  show: false
},
{
  label: '单位ID',
  field: 'unitId',
  component: 'Input',
  show: false
},
{
  label: '单位',
  field: 'unitName',
  component: 'Input',
  slot: 'unitSlot',
},
{
  label: '订单数量',
  field: 'orderQuantity',
  component: 'InputNumber',
},
{
  label: '已入库数',
  field: 'storageQuantity',
  component: 'InputNumber',
},
{
  label: '已排产数',
  field: 'productQuantity',
  component: 'InputNumber',
},
{
  label: '关闭数量',
  field: 'closeQuantity',
  component: 'InputNumber',
},
{
  label: '订单数量',
  field: 'orderQuantity',
  component: 'InputNumber',
},
{
  label: '已出货数',
  field: 'deliveryQuantity',
  component: 'InputNumber',
},
{
  label: '订单状态',
  field: 'billStatus',
  component: 'JDictSelectTag',
  defaultValue: 1,
  componentProps: {
    dictCode: "order_center_bill_status",
    stringToNumber: true,
  },
},
// {
//   label: '和云销售订单号',
//   field: 'hjSerialNumber',
//   component: 'Input',
// },
// {
//   label: '评审单号',
//   field: 'reviewCode',
//   component: 'Input',
// },
{
  label: '业务员ID',
  field: 'salesmanId',
  component: 'Input',
  show: false
},
{
  label: '业务员',
  field: 'salesmanId',
  component: 'JSelectUserByDept',
  componentProps: {
    isRadioSelection: true,
    rowKey: 'id',
    labelKey: 'realname',
    showButton: false
  },
},
{
  label: '客户ID',
  field: 'customerId',
  component: 'Input',
  show: false
},
{
  label: '客户',
  field: 'customerName',
  component: 'Input',
  slot: 'customerSlot'
},
{
  label: '接单组织ID',
  field: 'orderOrganizationId',
  component: 'Input',
  show: false
},
{
  label: '接单组织',
  field: 'orderOrganizationName',
  component: 'Input',
  slot: 'orderOrganizationSlot'
},
{
  label: '生产组织ID',
  field: 'produceOrganizationId',
  component: 'Input',
  show: false
},
{
  label: '生产组织',
  field: 'produceOrganizationName',
  component: 'Input',
  slot: 'produceOrganizationSlot'
},
{
  label: '是否OEM',
  field: 'oemNot',
  component: 'JDictSelectTag',
  componentProps: {
    dictCode: "yn",
    stringToNumber: true,
  },
},
{
  label: 'BOM是否完整',
  field: 'bomComplete',
  component: 'JDictSelectTag',
  defaultValue: 1,
  componentProps: {
    dictCode: "order_center_bom_complete",
    stringToNumber: true,
  },
},
// {
//   label: '非完整BOM是否安排生产',
//   field: 'notCompleteProduce',
//   component: 'JDictSelectTag',
//   defaultValue: 1,
//   componentProps: {
//     dictCode: "order_center_not_complete_produce",
//     stringToNumber: true,
//   },
// },
{
  label: '异步状态',
  field: 'syncStatus',
  component: 'JDictSelectTag',
  defaultValue: 1,
  componentProps: {
    dictCode: "order_center_sync_status",
    stringToNumber: true,
  },
},
{
  label: '备注',
  field: 'remark',
  component: 'Input',
},
{
  label: '第三方编码',
  field: 'thirdPartyCode',
  component: 'Input',
  ifShow: false
},
{
  label: '创建时间',
  field: 'createTime',
  component: 'DatePicker',
  componentProps: {
    showTime: true,
    valueFormat: 'YYYY-MM-DD HH:mm:ss'
  },
},
{
  label: '订单交期',
  field: 'orderDeliveryDate',
  component: 'DatePicker',
  componentProps: {
    showTime: true,
    valueFormat: 'YYYY-MM-DD'
  },
  show: false
},
{
  label: '供应类型',
  field: 'supplyType',
  component: 'Select',
  componentProps: {
    options: [{
      label: '自制',
      value: 0
    }, {
      label: '采购',
      value: 1
    }, {
      label: '委外',
      value: 2
    }]
  },
},
// TODO 主键隐藏字段，目前写死为ID
{
  label: '',
  field: 'id',
  component: 'Input',
  show: false
},
];

//子表表格配置
export const busSaleOrderItemColumns: JVxeColumn[] = [{
  title: '订单类型',
  key: 'billTypeName',
  type: JVxeTypes.normal,
  width: "200px",
},
{
  title: '订单单号',
  key: 'billCode',
  type: JVxeTypes.normal,
  width: "200px",
},
{
  title: '行号',
  key: 'rowNum',
  type: JVxeTypes.normal,
  width: "80px",
},
{
  title: '变更日期',
  key: 'changeTime',
  type: JVxeTypes.normal,
  width: "200px",
},
{
  title: '变更内容',
  key: 'changeContent',
  type: JVxeTypes.normal,
  width: "200px",
},
{
  title: '变更前',
  key: 'beforeChange',
  type: JVxeTypes.normal,
  width: "200px",
},
{
  title: '变更后',
  key: 'afterChange',
  type: JVxeTypes.normal,
  width: "200px",
},
]

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
